package uto.phone.flash.wind.base

import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.FrameLayout
import androidx.recyclerview.widget.RecyclerView

/**
 * RecyclerHolder 基类
 */
abstract class IHolder constructor(parent : ViewGroup,var activity : IActivity?= null, var adapter: IAdapter ?= null, var type: Int = 0)
    : RecyclerView.ViewHolder(FrameLayout(parent.context)),View.OnClickListener{

    /**
     * 初始化视图 向Item中填充布局 设置视图宽高 设置父布局点击监听
     */
    init {
        itemView.layoutParams = layoutParams()
        LayoutInflater.from(activity).inflate(layoutRes(),itemView as ViewGroup,true)

        itemView.setOnClickListener(this)

        initLayout()
        bindListener()
    }

    /**
     * 获取布局资源
     */
    abstract fun layoutRes(): Int

    /**
     * 初始化布局
     */
    open fun initLayout(){}

    /**
     * 绑定监听器
     */
    open fun bindListener(){}

    /**
     * 绑定数据
     */
    open fun bindData(any: Any?){}

    /**
     * 获取布局属性
     */
    open fun layoutParams(): ViewGroup.LayoutParams{
        return ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,ViewGroup.LayoutParams.WRAP_CONTENT)
    }


    /**
     * 父类控件点击
     */
    override fun onClick(v: View?) {}


}